// use std::cmp::{max, min};
use std::collections::HashMap;
use crate::solution::Solution;


impl Solution {
    pub fn longest_arith_seq_length_one(nums: Vec<i32>) -> i32 {
        let mut ans = 0;
        let mut map = HashMap::new();
        for j in 0..nums.len() {
            for i in 0..j {
                let d = nums[j] - nums[i];
                let cur = match  map.get(&(i, d)) {
                    Some(&cnt) => cnt + 1, // 不是分号";"！
                    None => 2,
                };
                map.insert((j, d), cur);
                ans = ans.max(cur);
            }
        }
        ans
    }

    // pub fn longest_arith_seq_length(nums: Vec<i32>) -> i32 {
    //     let mut minv : Option<&i32> = nums.iter().min();
    //     let mut maxv: Option<&i32> = nums.iter().max();
    //     let diff = maxv - minv;
    //     let mut ans : i32 = 1;
    //     for d in -diff..diff+1 {
    //         let mut f = HashMap::new();
    //         for num in nums {
    //             let prev = num - d;
    //             let cur = match f.get(&num) {
    //                 Some(&prev) => f.get(prev) + 1,
    //                 None => 0
    //             };
    //             f.insert(num, cur);
    //             ans = ans.max(cur);
    //         }
    //     }
    //     return ans
    // }
}


#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_1() {
        let nums = [3,6,9,12].to_vec();
        let ans = Solution::longest_arith_seq_length_one(nums);
        println!("ans: {}", ans);
    }

    #[test]
    fn test_2() {
        let foo = 12;
        let bar = 13;
        if foo == bar {
            println!("foo 等于 bar");
        } else if foo < bar {
            println!("foo 小于 bar");
        } else if foo != bar {
            println!("foo 不等于 bar");
        } else {
            println!("Nothing");
        }
    }
}